﻿using System;
using MvcTests.BestPractice.ApplicationService.Contracts;
using MvcTests.BestPractice.Core;
using MvcTests.BestPractice.Domain.Book;
using MvcTests.BestPractice.Model;
using MvcTests.BestPractice.Repository.Contracts;

namespace MvcTests.BestPractice.ApplicationService.Implements
{
    public class BookService:ApplicationService,IBookService
    {
        private readonly IBookRepository _bookRepository;

        public BookService(IRepositoryContext context,IBookRepository bookRepository) : base(context)
        {
            _bookRepository = bookRepository;
        }

        public Guid AddNewBook(BookModel bookModel)
        {
            var book = Book.NewBook(bookModel);

            _bookRepository.Add(book);
            Context.Commit();

            return book.Id;
        }
       
    }
}